<template>
  <div class="app-container">
    <el-radio-group v-model="queryParams.devicetype" @change="getList" style="margin-bottom: 30px;">
      <el-radio-button :label="0">地磁</el-radio-button>
      <el-radio-button :label="4">发光二维码</el-radio-button>
    </el-radio-group>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="所属项目" prop="projectId">
        <el-select v-model="queryParams.projectId" filterable clearable placeholder="请选择所属项目">
          <el-option
            v-for="item1 in projectList"
            :key="item1.id"
            :label="item1.name"
            :value="item1.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="总数" align="center" prop="totalNum" />
      <el-table-column label="已激活" align="center" prop="activationNum"/>
      <el-table-column label="已解绑" align="center" prop="unboundNum"/>
      <el-table-column label="未绑定" align="center" prop="notactiveNum" />
      <el-table-column label="维修" align="center" prop="maintenanceNum" />
      <el-table-column label="报废" align="center" prop="scrapNum" />
      <el-table-column label="剩余库存" align="center" prop="remainingNum" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button
            type="primary"
            icon="el-icon-view"
            @click="handleUpdate(row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改计费规则对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-table v-loading="xqLoading" :data="xqList">
        <el-table-column label="项目名称" align="center" prop="projectName" />
        <el-table-column label="厂商" align="center" prop="supplierName"  />
        <el-table-column label="总数" align="center" prop="totalNum" />
        <el-table-column label="已激活" align="center" prop="activationNum"/>
        <el-table-column label="已解绑" align="center" prop="unboundNum"/>
        <el-table-column label="未绑定" align="center" prop="notactiveNum" />
        <el-table-column label="维修" align="center" prop="maintenanceNum" />
        <el-table-column label="报废" align="center" prop="scrapNum" />
        <el-table-column label="剩余库存" align="center" prop="remainingNum" />
      </el-table>

      <pagination
        v-show="xqTotal>0"
        :total="xqTotal"
        :page.sync="xqQueryParams.pageNum"
        :limit.sync="xqQueryParams.pageSize"
        @pagination="getDetail"
      />
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getList, } from "@/api/parking/qrcodeStatist";
import { listAllFaParkProject,} from "@/api/config/projectPushManage";
export default {
  name: "GeoQuanyStati",
  dicts: ['project_push_type'],
  data() {
    return {
      form: {},// 表单参数
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 遮罩层
      loading: true,
      xqLoading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      xqTotal: 0,
      // 字典表格数据
      list: [],
      xqList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: undefined,
        devicetype:0,statisticsType:1,
      },
      xqQueryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      projectList:[],
    };
  },
  created() {
    this.listAllFaParkProject()
    this.getList();
  },
  methods: {
    async listAllFaParkProject(){//查询返回所有项目列表
      let res = await listAllFaParkProject()
      let data = res.data || []
      this.projectList = data
    },
    /** 查询字典类型列表 */
    getList() {
      this.loading = true;
      getList(this.queryParams).then(response => {
          this.list = response.rows || [];
          this.total = response.total || 0;
          this.loading = false;
        }
      );
    },
    handleUpdate(row) {
      this.open = true;
      this.title = "详情";
      this.xqQueryParams = {
        ...this.queryParams,
        pageNum: 1,
        pageSize: 10,statisticsType:2,projectId:row.projectId,
      }
      this.getDetail()
    },
    async getDetail(){
      this.xqLoading = true;
      let response = await getList(this.xqQueryParams)
      this.xqList = response.rows || [];
      this.xqTotal = response.total || 0;
      this.xqLoading = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
